package day20170411.homework.teacher.client;

import java.util.Scanner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import day20170411.homework.teacher.dao.TeacherDao;
import day20170411.homework.teacher.entity.TeacherEntity;
import utils.ArrayUtil;

public class TeacherTest {
	
	/**
	 * 持久层的实例化
	 */
	private TeacherDao dao = new TeacherDao();
	
	/**
	 * 老师类的实例
	 */
	private TeacherEntity teacherInfo = new TeacherEntity();
	
	/**
	 * 老师的的数组
	 */
	private TeacherEntity[] teacherArrays = new TeacherEntity[5];
	
	private Scanner scanner = null;
	
	/**
	 * 在所有方法之前执行
	 * @throws Exception
	 */
	@Before
	public void before() throws Exception {
		//第一位学生
		teacherInfo.setName("张丽");
		teacherInfo.setIdCard("123456789111111111");
		teacherInfo.setAge(20);
		teacherInfo.setSalary(20000.00);
		teacherInfo.setSex('女');
		teacherArrays[0] = teacherInfo;
		teacherInfo = new TeacherEntity();
		
		//第二位学生
		teacherInfo.setName("小张");
		teacherInfo.setIdCard("123456789111111112");
		teacherInfo.setAge(21);
		teacherInfo.setSalary(30000.00);
		teacherInfo.setSex('男');
		teacherArrays[1] = teacherInfo;
		teacherInfo = new TeacherEntity();
		
		//第三位学生
		teacherInfo.setName("小红");
		teacherInfo.setIdCard("123456789111111113");
		teacherInfo.setAge(28);
		teacherInfo.setSalary(10000);
		teacherInfo.setSex('男');
		teacherArrays[2] = teacherInfo;
		teacherInfo = new TeacherEntity();
		
		//第四位学生
		teacherInfo.setName("小王");
		teacherInfo.setIdCard("123456789111111114");
		teacherInfo.setAge(25);
		teacherInfo.setSalary(50000.00);
		teacherInfo.setSex('男');
		teacherArrays[3] = teacherInfo;
		
		scanner = new Scanner(System.in);
	}
	
	/**
	 * 增加老师测试
	 * @throws Exception
	 */
	@Test
	public void teacherCreateTest() throws Exception {
		
		//调用dao层的增加方法
		dao.teacherCreate(teacherArrays, teacherInfo);
		//调用工具类
		ArrayUtil.arrayPrint(teacherArrays);
		
	}
	
	/**
	 * 删除老师的测试
	 * @throws Exception
	 */
	@Test
	public void teacherDeleteTest() throws Exception {
		TeacherEntity[] teacherDelete = dao.teacherDelete(teacherArrays,"啊","小张","小红啊","张丽");
		ArrayUtil.arrayPrint(teacherDelete);
	}
	
	/**
	 * 修改老师的测试
	 * @throws Exception
	 */
	@Test
	public void teacherUpdateTest() throws Exception {
		
		//调用dao层的修改方法
		dao.teacherUpdate(teacherArrays,scanner);
		//调用工具类
		ArrayUtil.arrayPrint(teacherArrays);
	}
	
	/**
	 * 查询老师的测试
	 * @throws Exception
	 */
	@Test
	public void teacherRetrieve() throws Exception {
		ArrayUtil.arrayPrint(teacherArrays);
	}
	
	/**
	 * 在所有方法执行完再执行
	 * @throws Exception
	 */
	@After
	public void after() throws Exception {
		scanner.close();
	}
}
